layui.define(function (exports) {

    var LeftTabScroll = function () {
        this.default = {
            elem: null        //触发节点
        }
    }

    LeftTabScroll.prototype.init = function (options) {

        $.extend(true, this.default, options);

        if (this.default.elem === null) {
            throwError('Donate Error:请配置触发节点参数elem!');
        }
        var elem= this.default.elem;
        
        this.render();
    }
    var upHtml = `
        <button class="up"><i class="zkuasgm-icon">&#xe632;</i></button>
    `
    var downHtml = `
        <button class="down"><i class="zkuasgm-icon">&#xe633;</i></button>
    `
    LeftTabScroll.prototype.render = function () {
        console.log(this.elem)
        var config = this.default;
        var winHeight = $(window).height()
        var setHeight = parseInt(winHeight / 100) * 100 - 200
        var tagListUl = $(config.elem).find(".tag_list_left ul")
        var tagHeight = tagListUl.height();
        if(tagHeight>setHeight){
            $(config.elem).prepend(upHtml)
            $(config.elem).append(downHtml)
            layui.leftTabScroll.setTabHeight();
        }
        $(config.elem).find(".up").on("click",function(){
            var tagListUlMt = tagListUl.css("margin-top");
            var tagListSum = setHeight - tagHeight;
            console.log(tagListUlMt,tagListSum)
        })
        $(config.elem).find(".down").on("click",function(){
            var tagListUlMt = tagListUl.css("margin-top");
            if (tagListUlMt != 0 + "px" && !tagListUl.is(':animated')) {
                tagListUl.animate({ marginTop: "+=100px" }, 500);
            }
        })
        $(config.elem).find("li").on("click",function(){
            if($(this).hasClass("hov")){
                $(this).removeClass("hov")
            }else{
                $(this).addClass("hov")
            }
            
            // console.log($(this).css("margin-top"))
        })
        
    }
    LeftTabScroll.prototype.setTabHeight = function(){
        var winHeight = $(window).height()
        var tagHeight = $(this.default.elem).find(".tag_list_left ul").height();
        console.log(tagHeight)
        // // tagHeight = tagListUl.height();
        $(this.default.elem).find(".tag_list_left").height(parseInt( winHeight/100 )*100-200);
        $(this.default.elem).find("ul").height(tagHeight);
    }
    $(window).resize(function () {
        layui.leftTabScroll.setTabHeight();
        // console.log(this)
    })
    
    /**
     * 抛出异常错误信息。
     * @param {String} msg
     */
    function throwError(msg) {
        if (layer && layer != undefined) {
            layer.msg(msg, { icon: 5 });
        }
        throw new Error(msg);
        return;
    }
    var leftTabScroll = new LeftTabScroll();
    exports('leftTabScroll', leftTabScroll);
});